package com.ymatou.userservice.testcase;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.trading.operate.service.DeliveryValidationCall.JsonDeliveryValidationResult;
import com.ymatou.userservice.parameter.HistoryLoginIdRequestDtoBean;
import com.ymatou.userservice.service.HistoryLoginIdRequestDtoCall;
import com.ymatou.userservice.service.JsonHistoryLoginIdResult;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.UserCallService;
import com.ymttest.database.sqlwapper.DefaultWapper;
import com.ymttest.database.sqlwapper.UserLogoWapper;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.constant.ECode;
/**
*根据用户曾用名获取用户信息Test
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_HistoryLoginIdRequestDto{
	private static HistoryLoginIdRequestDtoBean historyloginidrequestdtoBean;
	private static HistoryLoginIdRequestDtoCall historyloginidrequestdtoCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("根据用户曾用名获取用户信息");
	}

	@Before
	public void caseUp() {
		historyloginidrequestdtoBean=new HistoryLoginIdRequestDtoBean();
		historyloginidrequestdtoCall=new HistoryLoginIdRequestDtoCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(historyloginidrequestdtoCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_HistoryLoginIdRequestDto_001() {
		Logger.start(true,"根据用户曾用名（修改过注册名）获取用户信息，成功");
		try {
			DefaultWapper database = new DefaultWapper();
			Map m=UserCallService.registerByMobile();
			Integer userId=Integer.valueOf(m.get("userid").toString());
			String HistoryLoginId=m.get("username").toString();
			String nloginid = "update_"+TestDataManager.getRandomNum(9);
			UserCallService.addLogoToUser(userId, "http://www.ymatou.com");
			UserCallService.resetNickName(userId,nloginid);
			Thread.sleep(1000);
			historyloginidrequestdtoBean.setHistoryLoginId(HistoryLoginId);
			historyloginidrequestdtoCall.setData(historyloginidrequestdtoBean);
			historyloginidrequestdtoCall.callService();	
			Logger.verifyEquals(ECode.SUCCESS, historyloginidrequestdtoCall.getCode(), "验证code");
			
			UserLogoWapper uw=new UserLogoWapper();
			Map m2 = database.selectUsers2(userId).get(0);
			Map m3=uw.selectLogoByUid(userId.toString());
			Map m4 = database.MobilePhoneAccount(userId).get(0);
			
			
			ArrayList<JsonHistoryLoginIdResult> jsonResutlList = historyloginidrequestdtoCall.getHistoryLoginIdResults();		
			Logger.verifyEquals(userId, jsonResutlList.get(0).getUserId(), "验证UserId");
			Logger.verifyEquals(m2.get("sLoginId"), jsonResutlList.get(0).getLoginId(), "验证LoginId");
			Logger.verifyEquals(m2.get("sLoginEmail"), jsonResutlList.get(0).getLoginEmail(), "验证LoginEmail");
			
			Logger.verifyEquals(m4.get("sAccountName"), jsonResutlList.get(0).getLoginMobile(), "验证LoginMobile");
			
			Logger.verifyEquals(m3.get("sLogoUrl").toString(), jsonResutlList.get(0).getLogoUrl(), "验证LogoUrl");
			Logger.verifyEquals("Normal", jsonResutlList.get(0).getUserType(), "验证UserType");			
			Logger.verifyEquals(0, jsonResutlList.get(0).getUserState(), "验证UserState");
			if(m2.get("sQQ") != null){
			Logger.verifyEquals(m2.get("sQQ"), jsonResutlList.get(0).getQQ(), "验证QQ");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_HistoryLoginIdRequestDto_002() {
		Logger.start(true,"根据用户现用名（改过注册名）获取用户信息，成功，信息为空");
		try {
			DefaultWapper database = new DefaultWapper();
			Map m=UserCallService.registerByMobile();
			Integer userId=Integer.valueOf(m.get("userid").toString());
			String HistoryLoginId=m.get("username").toString();
			String nloginid = "update_"+TestDataManager.getRandomNum(9);
			UserCallService.addLogoToUser(userId, "http://www.ymatou.com");
			UserCallService.resetNickName(userId,nloginid);
			Thread.sleep(1000);
			historyloginidrequestdtoBean.setHistoryLoginId(nloginid);
			historyloginidrequestdtoCall.setData(historyloginidrequestdtoBean);
			historyloginidrequestdtoCall.callService();	
			Logger.verifyEquals(ECode.SUCCESS, historyloginidrequestdtoCall.getCode(), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_HistoryLoginIdRequestDto_003() {
		Logger.start(true,"根据用户注册名（未修改过）获取用户信息，成功，信息为空");
		try {
			Map m=UserCallService.registerByMobile();
			Integer userId=Integer.valueOf(m.get("userid").toString());
			String HistoryLoginId=m.get("username").toString();
			historyloginidrequestdtoBean.setHistoryLoginId(HistoryLoginId);
			historyloginidrequestdtoCall.setData(historyloginidrequestdtoBean);
			historyloginidrequestdtoCall.callService();	
			Logger.verifyEquals(ECode.SUCCESS, historyloginidrequestdtoCall.getCode(), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}